// @ts-ignore
import {defineStore} from "pinia";
import {ThemeConfigState, UserState} from "/@/type/pinia";

// @ts-ignore
export const useThemeConfig = defineStore('themeConfig', {
    state: () : ThemeConfigState => ({
        themeConfig: {
            // 主题颜色
            theme: true,
            // 是否显示banner
            banner: true,
            // 是否显示背景图
            showBackImg: true,
            // 组件是否透明
            componentOpacity: true,
            // 菜单模式
            menuMode: 'vertical', // horizontal vertical
            // 布局
            layout: 'layout1',
            // 侧边栏颜色 rgba值
            siderColor: '',
            // 顶栏颜色 rgba值
            topBarColor: '',
            // 内容区域背景颜色 rgba值
            contentColor: '',
        },
    }),
    actions: {
        setThemeConfig(data:ThemeConfigState) {
            // @ts-ignore
            this.themeConfig = data
        },
        clearThemeConfig() {
            this.themeConfig = {
                theme: true,
                banner: true,
                showBackImg: true,
                componentOpacity: true,
                menuMode: 'vertical', // horizontal vertical
                layout: 'layout1',
                siderColor: '',
                topBarColor: '',
                contentColor: '',
            }
        },
    },
    // 持久化
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'themeConfig', // 存储在localStorage的key值
                paths: ['themeConfig'], // 需要持久化的数据
                storage: window.localStorage, // 指定持久化存储的对象
            },
        ],
    }
})

export const useUserConfig = defineStore('user', {
    state: () : UserState => ({
        userInfo: {
            id: -1,
            username: 'ZYF',
            avatar: '',
            token: null,
            date_joined: '',
            last_login: '',
            email: '',
            is_active: false,
            is_staff: false,
            is_superuser: false,
            groups: [],
        }
    }),
    actions: {
        setUserInfo(data:UserState) {
            // @ts-ignore
            this.userInfo = data
        },
        clearUserInfo() {
            this.userInfo = {
                id: -1,
                username: '',
                avatar: '',
                token: null,
                date_joined: '',
                last_login: '',
                email: '',
                is_active: false,
                is_staff: false,
                is_superuser: false,
                groups: [],
            }
        }
    },
    // 持久化
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'userInfo', // 存储在localStorage的key值
                paths: ['userInfo'], // 需要持久化的数据
                storage: window.localStorage, // 指定持久化存储的对象
            },
        ],
    }
})
